<template>
  <div>
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>
          <i class="el-icon-lx-group"></i> 后台实时弹幕信息
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="container">
      <div class="handle-box">
        <el-button type="primary" @click="show_send = true">发送弹幕</el-button>
      </div>
      <el-table :data="tableData" border class="table" ref="multipleTable" header-cell-class-name="table-header">
        <el-table-column prop="nickname" label="昵称"></el-table-column>
        <el-table-column prop="message" label="消息"></el-table-column>
        <el-table-column prop="createTime" label="创建时间" :formatter="dateFormat"></el-table-column>
      </el-table>
      <div class="pagination">
        <el-pagination background layout="total, prev, pager, next" :current-page="query.pageIndex" :page-size="query.pageSize" :total="query.pageTotal" @current-change="handlePageChange"></el-pagination>
      </div>
    </div>

    <!-- 编辑弹出框 -->
    <el-dialog title="发送弹幕" v-model="show_send" width="65%">
      <el-form ref="form" :model="list" label-width="100px">
        <el-form-item label="消息">
          <el-input v-model="from.message"></el-input>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="show_send = false">取 消</el-button>
          <el-button type="primary" @click="send">确 定</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import { upload, api } from "../../api/index";
import { formatDate } from "../../common/data";
import moment from "moment";
export default {
  inject: ["reload"],
  filters: {
    formatDate(time) {
      time = time * 1000;
      let date = new Date(time);
      console.log(new Date(time));
      return formatDate(date, "yyyy-MM-dd hh:mm");
    },
  },
  name: "basetable",
  data() {
    return {
      query: {
        pageNo: 1,
        pageTotal: 0,
      },
      search: "",
      tableData: [],
      from: {},
      show_send: false,
      pageTotal: 0,
      isChange: "",
      fileList: [],
      isDisabled: false,
      fileLists: [],
      dialogVisible: false,
    };
  },
  created() {
    this.getData();
  },
  mounted() { },
  methods: {
    joinpic(item) {
      return `https://www.yaozhuasocial.com/imgs/${item}`
    },
    dateFormat: function (row, column) {
      var date = row[column.property];
      if (date == undefined) {
        return "";
      }
      return moment(date).format("YYYY-MM-DD HH:mm:ss");
    },
    //创建分类
    send() {
      api('/web/imRecord/imSend', { message: this.from.message }).then((res) => {
        this.from = {};
        if (res.code === 2000) {
          this.$message.success(res.message);
          this.reload();
        } else {
          this.$message.error(res.message);
        }
      });
    },
    // 获取分类列表
    getData() {
      api('/web/imRecord/imList', {
        limit: 10,
        offset: this.query.pageNo,
      }).then((res) => {
        this.tableData = res.data.rows;
        this.query.pageTotal = res.data.total;
      });
    },
    // 分页导航
    handlePageChange(val) {
      // console.log(val);
      this.query.pageNo = val;
      this.getData();
    },
  },
};
</script>

<style lang='scss' scoped>
.handle-box {
  margin-bottom: 20px;
}

::v-deep .el-upload--text {
  background-color: #fff;
  border: none;
  border-radius: 6px;
  box-sizing: border-box;
  width: 200px;
  height: 100%;
  text-align: center;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.handle-select {
  width: 120px;
}

.handle-input {
  width: 300px;
  display: inline-block;
}

.table {
  width: 100%;
  font-size: 14px;
}

.red {
  color: #ff0000;
}

.green {
  color: #0ab618;
}

.mr10 {
  margin-right: 10px;
}

.table-td-thumb {
  display: block;
  margin: auto;
  width: 40px;
  height: 40px;
}

.crop-demo {
  display: flex;
  align-items: flex-end;
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  width: 148px;
  height: 148px;

  .pre-img {
    width: 146px;
    height: 146px;
    background: #f8f8f8;
    border: 1px solid #eee;
    border-radius: 5px;
    object-fit: cover;
  }

  .crop-input {
    position: absolute;
    width: 148px;
    height: 148px;
    left: 0px;
    top: 0px;
    opacity: 0;
    cursor: pointer;
  }

  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 148px;
    height: 148px;
    line-height: 148px;
    text-align: center;
  }
}

.picPreview {
  width: 100%;
}
</style>
